home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / bs941029.tgz / bbsx-941029.tar / bbsx / convind.c < prev    next >
C/C++ Source or Header  |  1994-10-29  |  2KB  |  97 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <sys/types.h>
  5. #include <pwd.h>
  6. #include <fcntl.h>
  7.  
  8. #include "bbs.h"
  9. #include "bbs.hd"
  10.  
  11. struct old_index {
  12.   long size;
  13.   long date;
  14.   int mesg;
  15.   char bid[LEN_BID+1];
  16.   char lifetime_h;
  17.   char subject[LEN_SUBJECT+1];
  18.   char lifetime_l;
  19.   char to[LEN_TO+1];
  20.   char at[LEN_AT+1];
  21.   char from[LEN_FROM+1];
  22.   char deleted;
  23. };
  24.  
  25.  
  26. const struct cmdtable cmdtable[1];
  27.  
  28. main() {
  29.  
  30.   struct passwd *pw;
  31.   struct index index;
  32.   struct old_index old_index;
  33.   int i;
  34.   int old_ind, new_ind;
  35.   char line[1204];
  36.  
  37.   if (getuid()) {
  38.     perror("permission denied");
  39.     return 1;
  40.   }  
  41.  
  42.   if (chdir(WRKDIR)) {
  43.     mkdir(WRKDIR, 0755);
  44.     if (chdir(WRKDIR)) halt();
  45.   }
  46.   
  47.   read_config();
  48.   
  49.   sprintf(line,"%s.o",INDEXFILE);
  50.   
  51.   if(link(INDEXFILE, line) == -1) { 
  52.     perror("can't rename old indexfile");
  53.     return;
  54.   }
  55.   if(unlink(INDEXFILE) == -1) { 
  56.     perror("can't remove old indexfile");
  57.     return;
  58.   }
  59.   
  60.   if ((new_ind = open(INDEXFILE, O_RDWR | O_CREAT, 0644)) < 0) { 
  61.     perror("can't open new indexfile");
  62.     return;
  63.   }
  64.   
  65.   if ((old_ind = open(line, O_RDONLY, 0644)) < 0) { 
  66.     perror("can't open old indexfile");
  67.     return;
  68.   }
  69.   
  70.   for (;;) {
  71.     if (read(old_ind,&old_index, sizeof(struct old_index)) < 1) break;
  72.     if (!old_index.deleted) {
  73.       index.size = old_index.size;
  74.       index.date = old_index.date;
  75.       index.mesg = old_index.mesg;
  76.       strcpy(index.bid, old_index.bid);
  77.       index.lifetime_h = old_index.lifetime_h;
  78.       index.lifetime_l = old_index.lifetime_l;
  79.       strcpy(index.subject, old_index.subject);
  80.       strcpy(index.to, old_index.to);
  81.       strcpy(index.orig_to, old_index.to);
  82.       strcpy(index.at, old_index.at);
  83.       strcpy(index.from, old_index.from);
  84.       index.flags = 0;
  85.       if(write(new_ind, &index, sizeof(struct index)) != sizeof(struct index))
  86.         halt();
  87.     }   
  88.   }
  89.   close(old_ind);
  90.   close(new_ind);
  91.   unlink(line);
  92.   
  93.   return;
  94. }
  95.     
  96.  
  97.